/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>平台可给商家提供站内信、手机短信、邮件三种通知方式。平台可以选择开启一种或多种通知方式供商家选择。</li>
          <li>开启强制接收后，商家不能取消该方式通知的接收。</li>
          <li>短消息、邮件需要商家设置正确号码后才能正常接收。</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>模板列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
    </div>

    <div class="tablebox">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="模板描述" prop="mmt_name" width="130"></el-table-column>
        <el-table-column label="站内信" width="130">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.mmt_message_switch"
              @change="update(scope.row)"
              :active-value="1"
              :inactive-value="0"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="手机短信" width="130">
          <template slot-scope="scope" v-if="scope.row.is_show == 1">
            <el-switch
              v-model="scope.row.mmt_short_switch"
              @change="update(scope.row)"
              :active-value="1"
              :inactive-value="0"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="邮件" width="130">
          <template slot-scope="scope" v-if="scope.row.is_show == 1">
            <el-switch
              v-model="scope.row.mmt_mail_switch"
              @change="update(scope.row)"
              :active-value="1"
              :inactive-value="0"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope" v-if="scope.row.is_show == 1">
            <el-button-group>
              <el-button size="small" @click="toEdit(scope)" icon="el-icon-edit-outline">编辑</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      shipping_name: null,
      shipping_code: null
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      this.request
        .get("/user/member_msg_tpl/page", {
          params: {
            page: that.currentPage,
            size: that.pageSize
          }
        })
        .then(function(res) {
          that.tableData = res.records;
          that.totalCount = res.total;
        });
    },
    update(row) {
      var that = this;
      this.request.put("/user/member_msg_tpl", row).then(function(res) {
        if (res.status == 1) {
          that.$message.success("修改成功");
          that.getPage();
        } else {
          that.$message.error("修改失败");
        }
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    toEdit(scope) {
      this.$router.push({
        name: "member_msg_detail",
        params: {
          mmt_code: scope.row.mmt_code
        }
      }); //进入编辑页 保存本页面页码数据
    }
  }
};
</script>
<style scoped>
</style>
